﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Tank.Resources;

namespace Tank.Role
{
    public class Player
    {
        private Tank.Data.Direction indexDirection = Data.Direction.up;
        private bool idnexStop = true;
        private Tank.Data.play indexPlay;
        public Point indexPoint;
        public Bullet indexBullet=null;
        /// <summary>
        /// 当前运动方向
        /// </summary>
        public Tank.Data.Direction IndexDirection
        {
            get { return indexDirection; }
            set { indexDirection = value; }
        }

        /// <summary>
        /// 获取当前玩家
        /// </summary>
        public Tank.Data.play IndexPlay
        {
            get { return indexPlay; }
        }
        /// <summary>
        /// 当前坦克是否停止 true停止
        /// </summary>
        public bool IdnexStop
        {
            get { return idnexStop; }
            set { idnexStop = value; }
        }

        /// <summary>
        /// 玩家类
        /// </summary>
        /// <param name="play">那个玩家</param>
        /// <param name="p">玩家坐标</param>
        public Player(Tank.Data.play play, Point p)
        {
            this.indexPlay = play;
            this.indexPoint = p;
        }

        /// <summary>
        /// 获取玩家坦克图标
        /// </summary>
        /// <returns></returns>
        public Image getImage()
        {
            switch (indexDirection)
            {
                case Data.Direction.up:
                    if (indexPlay == Data.play.one)
                        return ImageResources.playerOneUp;
                    else
                        return ImageResources.playerTwoUp;
                case Data.Direction.down:
                    if (indexPlay == Data.play.one)
                        return ImageResources.playerOneDown;
                    else
                        return ImageResources.playerTwoDown;
                case Data.Direction.left:
                    if (indexPlay == Data.play.one)
                        return ImageResources.playerOneLeft;
                    else
                        return ImageResources.playerTwoLeft;
                case Data.Direction.right:
                    if (indexPlay == Data.play.one)
                        return ImageResources.playerOneRight;
                    else
                        return ImageResources.playerTwoRight;
                default:
                    if (indexPlay == Data.play.one)
                        return ImageResources.playerOneUp;
                    else
                        return ImageResources.playerTwoUp;
            }
        }

        /// <summary>
        /// 获取玩家坦克坐标
        /// </summary>
        /// <returns></returns>
        public Point getPoint()
        {
            if (Data.playerMove && idnexStop == false)
            {
                bool isCollision;
                indexPoint = new TankCollision().getTankPoint(indexDirection, indexPoint,out isCollision);
                //switch (indexDirection)
                //{
                //    case Data.Direction.up:
                //        //缺少判断是否碰撞
                //        indexPoint = new Point(indexPoint.X, indexPoint.Y - Data.MoveSize);
                //        break;
                //    case Data.Direction.down:
                //        //缺少判断是否碰撞
                //        indexPoint = new Point(indexPoint.X, indexPoint.Y + Data.MoveSize);
                //        break;
                //    case Data.Direction.left:
                //        //缺少判断是否碰撞
                //        indexPoint = new Point(indexPoint.X - Data.MoveSize, indexPoint.Y);
                //        break;
                //    case Data.Direction.right:
                //        //缺少判断是否碰撞
                //        indexPoint = new Point(indexPoint.X + Data.MoveSize, indexPoint.Y);
                //        break;

                //}
                //Data.playerMove = false;
            }
            return indexPoint;
        }

    }
}
